Frame Grabber

This script traverses the frame tree from the _Top on down and reports the contents of this window. Contrast this report with the HTML source found in "Document Source" of the View menu.


Discussion

Preformatted text provides proper indentation as the script traverses the frame tree. The parameter level stores the degree of recursion and hence the current level of indentation. Contrast this report with the HTML provided by "Document Source" under the "View" menu.
function recurseFrames(aFrame, level)
{
    // report the name
    for (var i = 0; i < level; i++) document.write("  ")
    if (aFrame.name == "")
        document.writeln("<b>&lt;unnamed frame&gt;</b>")
    else
        document.writeln("<b>"+aFrame.name+"</b>")
    
    // recurse for children
    for (var i = 0; i < aFrame.frames.length; i++)
        recurseFrames(aFrame.frames[i], level+1)
}
Copyright ©2000 by Charles River Media, All Rights Reserved